#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int Sum(string str)
{
    int sum = 0;
    for (int i = 0; i < str.size(); i++)
    {
        int tmp = str[i] * 31 + str[i];
        sum += tmp;
    }
    return sum;
}
vector<int> findAnagrams(string s, string p) {
    int s_sum = 0, p_sum = 0, len = 0;
    vector<int> v;
    p_sum = Sum(p);
    for (int left = 0, right = 0; right < s.size(); right++)
    {
        int tmp= s[right] * 31 + s[right];
        s_sum += tmp;
        len++;
        if (s_sum == p_sum)
        {
            v.push_back(left);
        }
        while (len == p.size())
        {
            s_sum = s_sum - s[left] * 31 - s[left];
            left++;
            len--;
        }
    }
    return v;
}
int main()
{
    string s = "af";
    string p = "be";
    vector<int> a=findAnagrams(s, p);
    for (auto& e : a)
    {
        cout << e << " ";
    }
	return 0;
}